//
//  WPNavigationViewController.swift
//  WB
//
//  Created by 汪鹏 on 2016/12/14.
//  Copyright © 2016年 汪鹏. All rights reserved.
//

import UIKit

class WPNavigationViewController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 隐藏系统的导航栏
        navigationBar.isHidden = true
    }
    
    // 重写push方法，所有的push操作都会走这个方法
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        if viewControllers.count > 0 {
            
            viewController.hidesBottomBarWhenPushed = true;
            
            if let vc = viewController as? WPBaseViewController {
                
                var title = "返回"
                
                if childViewControllers.count == 1 {
                    
                    title = childViewControllers.first?.title ?? "返回"
                }
                
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(backToParent), isBack:true)
            }
        }
        
        super.pushViewController(viewController, animated: true)
    }
    
    @objc private func backToParent(){
        popViewController(animated: true)
    }
}
